<?php

class Upload extends Controller {

	public function run() {
		set_time_limit(0);

		if (empty($_GET['plugin']) || empty($_GET['ver'])) {
			$this->template('message', array('message' => '参数错误'));
		}

		$plugin = $_GET['plugin'];
		$ver = $_GET['ver'];

		if (empty($_POST['submit'])) {
			try {
				$dirs = Sdk\lib\Core::GetDirs($plugin, $ver);
			} catch (Exception $e) {
				$this->template('message', array('message' => '应用目录拉取失败<br />' . $e->getMessage()));
			}
			$this->template('uploadSelect', array('dirs' => $dirs, 'plugin' => $plugin, 'ver' => $ver));
		}

		if (empty($_POST['method'])) {
			try {
				Sdk\lib\Core::UploadPlugin($plugin, $ver, !empty($_POST['dir']) ? $_POST['dir'] : array());
			} catch (Exception $e) {
				$this->template('message', array('message' => '应用提审失败<br />' . $e->getMessage()));
			}
		} else {
			try {
				Sdk\lib\Core::ReviewByGit($plugin, $ver);
			} catch (Exception $e) {
				$this->template('message', array('message' => '应用提审失败<br />' . $e->getMessage()));
			}
		}

		$this->template('message', array('message' => '应用已提审，请到<a href="https://dev.witframe.com">WitFrame开放平台</a>中确认'));
	}
}